<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li{
            list-style: none;
            float: left;
            width: 80px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            background-color: gray;
            margin-right: 10px;
            cursor: pointer;
        }

        .active{
            background-color: red;
        }
    </style>
</head>
<body>
    <div id="app">
        <ul>
            <li v-show="pageNo>1" @click="page(pageNo-1)">上一页</li>
            <li v-for="(item,index) in jisuan" :key="index" :class="{active:pageNo==item}" @click="page(item)">
                {{item}}
            </li>
            <li v-show="pageNo<totalPage" @click="page(pageNo+1)">下一页</li>
        </ul>
    </div>
</body>
</html>
<script src="js/vue.min.js"></script>
<script>
    var app=new Vue({
        el:"#app",
        data:{
            pageNo:1,//当前页码数
            pageSize:5,//每页显示的条数
            totalPage:15,//总页数
            arr:[]
        },
        computed:{
            jisuan:function(){
                //前2，后2
                var begin=this.pageNo-2;
                var end=this.pageNo+2;
                if(begin<1){//开始页码比1还小
                    begin=1;
                    end=begin+(this.pageSize-1);
                }
                if(end>this.totalPage){//结束页码比总页数还大
                    end=this.totalPage;
                    begin=this.totalPage-(this.pageSize-1);
                }
                //计算页码
                var pages=[];
                for(var i=begin;i<=end;i++){
                    pages.push(i);
                }
                return pages;
            }
        },
        methods:{
            page:function(val){
                this.pageNo=val;
            }
        }
    });
</script>